package com.scw.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.scw.model.Tip;
import com.scw.service.TipService;

/**
 * 标签管理类
 * @author 王华聪
 *
 */
public class TipAction {
	private TipService tipService;
	private Tip tip;
	/**
	 * 添加标签
	 * @return
	 */
	public String add(){
		return "add";
	}
	/**
	 * 保存
	 * @return
	 */
	public String save(){
		tipService.save(tip);
		return "list";
	}
	
	/**
	 * 修改
	 * @return
	 */
	public String edit(){
		HttpServletRequest req=ServletActionContext.getRequest();
		String id=req.getParameter("id");
		tip=tipService.get(Long.valueOf(id));
		req.setAttribute("tip", tip);
		return "edit";
	}
	/**
	 * 更新
	 * @return
	 */
	public String update(){
		tipService.update(tip);
		return "list";
	}
	/**
	 * 标签list
	 * @return
	 */
	public String list(){
		HttpServletRequest req= ServletActionContext.getRequest();
		String id=req.getParameter("id");
		List<Tip> list= new ArrayList<Tip>();
		list=tipService.findByUserId(Long.valueOf(id));
		req.setAttribute("list", list);
		return "listByUser";
	}
	
	
	public Tip getTip() {
		return tip;
	}
	public void setTip(Tip tip) {
		this.tip = tip;
	}
	public TipService getTipService() {
		return tipService;
	}
	public void setTipService(TipService tipService) {
		this.tipService = tipService;
	}
	
	
}
